package com.sise.wangzhan;

import com.netflix.client.ClientFactory;
import com.netflix.config.ConfigurationManager;
import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.PingUrl;
import com.netflix.loadbalancer.Server;
import com.netflix.niws.client.http.RestClient;
import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname TestPingUrl
 * @Description TODO
 * @Date 2020/3/26 17:10
 * @Created by wangzhan
 */
@SuppressWarnings("deprecation")
public class TestPingUrl {
    public static void main(String[] args) throws InterruptedException, IOException {
        /*BaseLoadBalancer Ib = new BaseLoadBalancer();

        List<Server> servers = new ArrayList<Server>();
        servers.add(new Server("localhost", 8081));
        servers.add(new Server("localhost", 8085));
        Ib.addServers(servers);
        Ib.setPing(new PingUrl());

        System.out.println(Ib.getPing().toString()+"=============================");
        Ib.setPingInterval(2);
        System.out.println(Ib.getPingInterval()+"----------------------------");

        Thread.sleep(6000);

        for (Server s : Ib.getAllServers()){
            System.out.println(s.getHostPort()+"   State:"+s.isAlive());
        }*/

        ConfigurationManager.loadPropertiesFromResources("application.properties");
        RestClient client = (RestClient) ClientFactory.getNamedClient("wang-client");

        Thread.sleep(6000);
        List<Server> servers = client.getLoadBalancer().getReachableServers();
        System.out.println(servers.size());
        for (Server s:servers){
            System.out.println(s.getHostPort()+"   State:"+s.isAlive());
        }


    }
}
